package com.xjscrm.console.chat.mq.impl;

import com.uzai.mobile.collect.api.dto.MicaTransDto;
import com.uzai.mobile.collect.api.dto.msg.MicaTaskResultMsg;
import com.uzai.mobile.collect.api.enums.MicaMsgType;
import com.xjscrm.console.chat.mq.MsgHandler;
import com.xjscrm.console.service.customer.chat.ChatTalkRecordService;
import com.xjscrm.console.service.customer.chat.ChatTalkSessionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author mingyang.chen create in 2024/3/11 18:14
 */
@Component
@Slf4j
public class TaskResulMsgHandler implements MsgHandler<MicaTaskResultMsg> {

    @Autowired
    private ChatTalkSessionService chatTalkSessionService;

    @Autowired
    private ChatTalkRecordService chatTalkRecordService;

    @Override
    public MicaMsgType msgType() {
        return MicaMsgType.TASK_RESULT;
    }

    @Override
    public Class<MicaTaskResultMsg> msgClass() {
        return MicaTaskResultMsg.class;
    }

    @Override
    public void doHandle(MicaTaskResultMsg micaTaskResultMsg) {
        MicaTransDto micaTransDto = baseCache.get();

        Long taskId = micaTaskResultMsg.getTaskId();
        Boolean success = micaTaskResultMsg.getSuccess();

        log.info("taskId: {}, success: {}", taskId, success);

        //
        chatTalkRecordService.deleteOfRecallIfAbsent(micaTransDto.getMerId(), taskId);
    }
}
